/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PackagerView.java
 *
 * Created on 05/03/2011, 10:40:28 PM
 */
package packagerars;

import java.awt.Image;
import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;

/**
 *
 * @author Ronald
 */
public class PackagerView extends javax.swing.JFrame {
    private String newline;

    /** Creates new form PackagerView */
    public PackagerView() {
        this.setIconImage(new ImageIcon(getClass().getResource("paquete.png")).getImage());
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButtonInicio = new javax.swing.JButton();
        jPaneDatosFtp = new javax.swing.JPanel();
        jTFHost = new javax.swing.JTextField();
        jTFClave = new javax.swing.JTextField();
        jTFUsuario = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTFPuerto = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jCheckBoxFTP = new javax.swing.JCheckBox();
        jPanel3 = new javax.swing.JPanel();
        jTFDirectorioRaiz = new javax.swing.JTextField();
        jButtonExaminarArchivo = new javax.swing.JButton();
        jTFDirectorioCsv = new javax.swing.JTextField();
        jButtonExaminarCsv = new javax.swing.JButton();
        jComboAgrupacion = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jTextNombreArchivo = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTAMensaje = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Empaquetador");
        setResizable(false);

        jButtonInicio.setText("Iniciar Proceso");
        jButtonInicio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonInicioActionPerformed(evt);
            }
        });

        jPaneDatosFtp.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos FTP"));

        jLabel1.setText("Host");

        jLabel2.setText("Usuario");

        jLabel3.setText("Clave");

        jTFPuerto.setText("21");

        jLabel4.setText("Puerto:");

        javax.swing.GroupLayout jPaneDatosFtpLayout = new javax.swing.GroupLayout(jPaneDatosFtp);
        jPaneDatosFtp.setLayout(jPaneDatosFtpLayout);
        jPaneDatosFtpLayout.setHorizontalGroup(
            jPaneDatosFtpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPaneDatosFtpLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPaneDatosFtpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPaneDatosFtpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jTFPuerto, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTFHost, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 184, Short.MAX_VALUE)
                    .addComponent(jTFClave, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTFUsuario, javax.swing.GroupLayout.Alignment.LEADING))
                .addGap(320, 320, 320))
        );
        jPaneDatosFtpLayout.setVerticalGroup(
            jPaneDatosFtpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPaneDatosFtpLayout.createSequentialGroup()
                .addGroup(jPaneDatosFtpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTFHost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPaneDatosFtpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPaneDatosFtpLayout.createSequentialGroup()
                        .addComponent(jTFUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPaneDatosFtpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTFClave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3)))
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPaneDatosFtpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTFPuerto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jCheckBoxFTP.setSelected(true);
        jCheckBoxFTP.setText("Envio por FTP.");
        jCheckBoxFTP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxFTPActionPerformed(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos de Compresión"));

        jButtonExaminarArchivo.setText("Examinar");
        jButtonExaminarArchivo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonExaminarArchivoActionPerformed(evt);
            }
        });

        jButtonExaminarCsv.setText("Examinar");
        jButtonExaminarCsv.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonExaminarCsvActionPerformed(evt);
            }
        });

        jComboAgrupacion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "agrupar", "no_agrupar" }));
        jComboAgrupacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboAgrupacionActionPerformed(evt);
            }
        });

        jLabel5.setText("Directorio Raiz:");

        jLabel6.setText("Archivo Csv:");

        jLabel7.setText("Tipo Agrupacion:");

        jLabel8.setText("Nombre Archivo:");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7))
                .addGap(22, 22, 22)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jComboAgrupacion, 0, 155, Short.MAX_VALUE)
                    .addComponent(jTextNombreArchivo, javax.swing.GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE)
                    .addComponent(jTFDirectorioCsv, javax.swing.GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE)
                    .addComponent(jTFDirectorioRaiz, javax.swing.GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonExaminarArchivo, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonExaminarCsv, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTFDirectorioRaiz, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonExaminarArchivo))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTFDirectorioCsv, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6)
                            .addComponent(jButtonExaminarCsv)))
                    .addComponent(jLabel5))
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(jTextNombreArchivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel8)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboAgrupacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addContainerGap(22, Short.MAX_VALUE))
        );

        jTAMensaje.setColumns(20);
        jTAMensaje.setRows(5);
        jScrollPane1.setViewportView(jTAMensaje);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(117, 117, 117)
                        .addComponent(jButtonInicio))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jCheckBoxFTP, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPaneDatosFtp, javax.swing.GroupLayout.Alignment.LEADING, 0, 330, Short.MAX_VALUE)
                            .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 330, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBoxFTP)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPaneDatosFtp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonInicio)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonExaminarArchivoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonExaminarArchivoActionPerformed
        // TODO add your handling code here:
        JFileChooser fc = new JFileChooser();
        fc.setDialogTitle("Ubicacion del archivo resultante");
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int returnVal = fc.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            System.out.println("Abrir: " + file.getAbsolutePath());
            jTFDirectorioRaiz.setText(file.getAbsolutePath());

        } else {
            System.out.println("Comando cancelado por el usuario." + newline);
        }
    }//GEN-LAST:event_jButtonExaminarArchivoActionPerformed

    private void jCheckBoxFTPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxFTPActionPerformed

        if (jCheckBoxFTP.isSelected()) {
            jTFUsuario.setEnabled(true);
            jTFHost.setEnabled(true);
            jTFClave.setEnabled(true);
            jTFPuerto.setEnabled(true);
        } else {
            jTFUsuario.setEnabled(false);
            jTFHost.setEnabled(false);
            jTFClave.setEnabled(false);
            jTFPuerto.setEnabled(false);
        }
    }//GEN-LAST:event_jCheckBoxFTPActionPerformed

    private void jButtonExaminarCsvActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonExaminarCsvActionPerformed
        // TODO add your handling code here:
        // TODO add your handling code here:
        JFileChooser fc = new JFileChooser();
        fc.setDialogTitle("Ubicacion del archivo resultante");
        int returnVal = fc.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            System.out.println("Abrir: " + file.getAbsolutePath());
            jTFDirectorioCsv.setText(file.getAbsolutePath());

        } else {
            System.out.println("Comando cancelado por el usuario." + newline);
        }
    }//GEN-LAST:event_jButtonExaminarCsvActionPerformed

    private void jButtonInicioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonInicioActionPerformed
        jTAMensaje.setText("");
        Compresor compresor =  new Compresor();
        compresor.compresor(jTFDirectorioRaiz.getText(),
                            jTFDirectorioCsv.getText() ,
                            jComboAgrupacion.getSelectedItem().toString() ,
                            jTFUsuario.getText(),
                            jTFClave.getText(),
                            jTFHost.getText(),
                            jTFPuerto.getText(),
                            jCheckBoxFTP.isSelected(),
                            jTAMensaje,
                            jTextNombreArchivo.getText());
    }//GEN-LAST:event_jButtonInicioActionPerformed

    private void jComboAgrupacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboAgrupacionActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboAgrupacionActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new PackagerView().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonExaminarArchivo;
    private javax.swing.JButton jButtonExaminarCsv;
    private javax.swing.JButton jButtonInicio;
    private javax.swing.JCheckBox jCheckBoxFTP;
    private javax.swing.JComboBox jComboAgrupacion;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPaneDatosFtp;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTAMensaje;
    private javax.swing.JTextField jTFClave;
    private javax.swing.JTextField jTFDirectorioCsv;
    private javax.swing.JTextField jTFDirectorioRaiz;
    private javax.swing.JTextField jTFHost;
    private javax.swing.JTextField jTFPuerto;
    private javax.swing.JTextField jTFUsuario;
    private javax.swing.JTextField jTextNombreArchivo;
    // End of variables declaration//GEN-END:variables
}
